﻿#include "filelistitem.h"
#include "ui_filelistitem.h"
#include <QPixmap>
#include <protocol.h>

FileListItem::FileListItem(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::FileListItem)
{
    ui->setupUi(this);
    // ui->lb_fileName->setFixedWidth(200);
    // ui->lb_fileSize->setFixedWidth(100);
    // ui->lb_fileType->setFixedWidth(80);
    // ui->lb_fileTime->setFixedWidth(200);
}

FileListItem::~FileListItem()
{
    delete ui;
}

void FileListItem::setFileSize(QString Size)
{
    ui->lb_fileSize->setText(Size);
}

void FileListItem::setFileImg(QString imgPath)
{
    QPixmap pixmap(imgPath);
    ui->lb_img->setPixmap(pixmap);

}

void FileListItem::setFileName(QString Name)
{
    ui->lb_fileName->setText(Name);
}

void FileListItem::setFIleType(QString fileType)
{
    QString iconPath;

    if (fileType == FILE_TYPE_FOLDER) {
        iconPath = FILE_TYPE_FOLDER_ICON;
    } else if (fileType == FILE_TYPE_VIDEO) {
        iconPath = FILE_TYPE_VIDEO_ICON;
    } else if (fileType == FILE_TYPE_MUSIC) {
        iconPath = FILE_TYPE_MUSIC_ICON;
    } else if (fileType == FILE_TYPE_IMAGE) {
        iconPath = FILE_TYPE_IMAGE_ICON;
    } else if (fileType == FILE_TYPE_TEXT) {
        iconPath = FILE_TYPE_TEXT_ICON;
    } else if (fileType == FILE_TYPE_ZIP) {
        iconPath = FILE_TYPE_ZIP_ICON;
    } else {
        iconPath = FILE_TYPE_UNKNOW_ICON;
    }

    ui->lb_fileType->setText(fileType);
    setFileImg(iconPath);
}

void FileListItem::setFileTime(QString Time)
{
    ui->lb_fileTime->setText(Time);
}

QString FileListItem::getFileName()
{
    return ui->lb_fileName->text();
}

QString FileListItem::getFileType()
{
    return ui->lb_fileType->text();
}
